Hi! I have written this code in the attachement. The 2 functions must have a bool return-value. The Compiler says me, that function 'identifyFunction' is terminated with this Error: "function terminated without executing return Statement".
bandchef - Mon Feb 24 03:59:19 EST 2014 |
Re: Return-Value Problem Hello bandchef, you just need to add a return statement after the "if(ht == modifyObject)" part. As in case ht is not modifyObject currently your identifyFunction doesn't return a value.
- Michael |
Re: Return-Value Problem MichaelGeorg - Mon Feb 24 05:14:57 EST 2014 Hello bandchef, you just need to add a return statement after the "if(ht == modifyObject)" part. As in case ht is not modifyObject currently your identifyFunction doesn't return a value.
- Michael Thank you for your answer! What do you exactly mean by writing: "you just need to add a return statement after the "if(ht == modifyObject)" part."? What is a return Statement? I think, that if the if-statement is true, the true block will return a 'true' by using the statement "return true", isn't it? |
Re: Return-Value Problem bandchef - Mon Feb 24 05:23:17 EST 2014 Thank you for your answer! What do you exactly mean by writing: "you just need to add a return statement after the "if(ht == modifyObject)" part."? What is a return Statement? I think, that if the if-statement is true, the true block will return a 'true' by using the statement "return true", isn't it? Bandchef,
The thing is, if ht != modifyObject, the function does not return a value. What should identifyFunction return in this case? The current else clause only works for th inner condition, not the outer condition.
-Marcel
|
Re: Return-Value Problem Ah, thank you Marcel! The function should return a false in case of ht != modifyObject. The problem now is, that the function always returns false. Attachments for you.dxl |
Re: Return-Value Problem bandchef - Mon Feb 24 07:30:52 EST 2014 Ah, thank you Marcel! The function should return a false in case of ht != modifyObject. The problem now is, that the function always returns false. Code of identifyFunction now looks fine to me, so perhaps the problem is in skip you are using. Or the problem is in line 57, where you have a return in your loop through the history items. This way you will always only process the first history item, is this your intention? - Michael |
Re: Return-Value Problem bandchef - Mon Feb 24 07:30:52 EST 2014 Ah, thank you Marcel! The function should return a false in case of ht != modifyObject. The problem now is, that the function always returns false. As Michael stated, the code round line 57 doesn't look right. If you're checking for changes you'd probable want to return true here only in the identifyFunction returns true. It looks as though there's some efficiency to be won in this piece of code, as well. There's another possible gotcha in this code: are you aware that the "for str_Attribute in s do" line iterates over the values of the skip list, not over the keys? Not knowing what's in you skiplist makes it hard to decode. A guess at what you're trying to achieve (assuming the attributes are the keys in the skiplist):
bool checkForChanges(Module m, Skip s)
{
History h
for h in m do {
if (h.type == modifyObject) {
if (find(s, h.attrName)) {
return true
}
}
}
return false
}
Skip s = createString
put(s, "Object Text", "Any old value, doesn't matter")
put(s, "Object Short Text", 1)
if (checkForChanges(current Module, s)) {
print "Module changed in one of the attributes\n"
}
else {
print "Module not changed\n"
}
Good luck. |
Re: Return-Value Problem bandchef - Mon Feb 24 07:30:52 EST 2014 Ah, thank you Marcel! The function should return a false in case of ht != modifyObject. The problem now is, that the function always returns false. I presume "checkForChanges()" should return "true" when even a single qualifying History was detected. Change line 57:
Insert a new line after #59:
M_vdLaan is probably right about an error in your Key/Data values in the Skip (good catch). Let's find out: Change line #49
Change line #51
Yes, the Skip "find" function searches for the "Key", whereas the Skip loop loops through the "data". The "key" function (my new line #49) works inside such a loop and is pretty routine when dealing with Skip loops. Note it must be "caste", which is the "string" word in that line. Note that the interpreter will correctly flag an error if the "key" function is used inside the wrong loop. -Louie Even after all these years and 1000s of "Skips" I still get confused (it's one of my several conceptual "black holes"). So I declare all my Skips with a comment explicitely stating what is the "Key" and what is the "Data"; like this:
I routinely find all references in the code to "skpObjects" (create, put, get, and loop) and make sure I'm dealing with it as specified in the comment. Errors associated with using the Skip inconsistently are particularly hard to find, at least for me.
|
Re: Return-Value Problem bandchef - Mon Feb 24 07:30:52 EST 2014 Ah, thank you Marcel! The function should return a false in case of ht != modifyObject. The problem now is, that the function always returns false. Scattering "return" statements around inside a function can get confusing. In this case, you can drastically improve function "identifyFunction" with this:
Or this:
"h.attrName" will trigger a run-time error unless "ht" is of the correct type (modifyObject is one of the correct types). Thus, reversing the order will not work:
-Louie
-Louie |